'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    const { DATE } = Sequelize;
    
    // 检查cooperation_date字段是否已存在
    const tableInfo = await queryInterface.describeTable('suppliers');
    if (!tableInfo.cooperation_date) {
      // 在suppliers表中添加cooperation_date字段
      await queryInterface.addColumn('suppliers', 'cooperation_date', {
        type: DATE,
        allowNull: true,
        comment: '合作开始时间'
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 检查cooperation_date字段是否存在
    const tableInfo = await queryInterface.describeTable('suppliers');
    if (tableInfo.cooperation_date) {
      // 删除cooperation_date字段
      await queryInterface.removeColumn('suppliers', 'cooperation_date');
    }
  }
};